<html>
<body>

<?php

function process_dir($dirpath)
{
//echo "Directory(1): $dirpath <br>\n";
if ($dirh = opendir($dirpath))
{ 
 //echo "Directory handle: $dirh   \n"; 
 //echo "Files:<br>\n"; 
 $dirlist=array();

 while (false !== ($file = readdir($dirh)))
 { 
  //echo "File(2): $dirpath\\$file<br>\n";
  if (strpos($file,'.')===0) {continue;}
  $file_path=$dirpath.'\\'.$file;
  //$file_path=$dirpath.'\\CvArea.cpp';
  if (is_dir($file_path))
  {
   $dirlist[]=$file_path;
  }
  else
  {
   $changed=false;
   if (strpos($file,'.cpp')===false) {continue;}
   if (!$fhandle = fopen ($file_path, "r")) {echo "Failed to open $file_path<br>\n"; continue;} 
   echo "File $file_path<br>\n";
   $contents = fread ($fhandle, filesize ($file_path));
   fclose ($fhandle);
   if (strpos($contents,'m_funcname')!==false) {continue;}
   $ac=explode('::',$contents);
   $nameok=true;
   for ($i=count($ac)-1;$i>0;$i--)
    {
     if (!$nameok)
      {
       $ac[$i]=$ac[$i]."::".$ac[$i+1];
       unset($ac[$i+1]);
      }
     $nameok=false;
     $pos=strpos($ac[$i],'(');
     if ($pos<40)
      {
       $funcname=substr($ac[$i],0,$pos);
       if (!strlen($funcname)) {continue;}
       if (strpos($funcname,'iterator')!==false) {continue;}
       if (strpos($funcname,'CvGlobals')!==false) {continue;}
       if (strpos($funcname,'INVALID_INDEX')!==false) {continue;}
       $pos=max(strrpos($ac[$i-1],' '),strrpos($ac[$i-1],"\n"));
       $classname=substr($ac[$i-1],$pos+1);
       if (!strlen($classname)) {continue;}
       if (strpos($classname,'std')!==false) {continue;}
       if (strpos($classname,'python')!==false) {continue;}
       $name=$classname.'::'.$funcname;
       if (strpos($name,'"')!==false) {continue;}
       //if (strpos($name,'*')!==false) {continue;}
       if (strpos($name,'(')!==false) {continue;}
       if (strpos($name,')')!==false) {continue;}
       if (strpos($name,'&')!==false) {continue;}
       if (strpos($name,'#')!==false) {continue;}
       if (strpos($name,"\\")!==false) {continue;}
       if (strpos($name,'_Alloc')!==false) {continue;}
       if (strpos($name,'size_type')!==false) {continue;}
       if (strpos($name,'CvGlobals::init')!==false) {continue;}

       $pos_sk=strpos($ac[$i],"{");
       if (strpos($ac[$i],"\n")>$pos_sk) {continue;}

       $finalfuncname=$file."-".$name;
       $len=strlen($finalfuncname);
       if ($len>63)
        {
         $finalfuncname=substr($finalfuncname,0,63);
        }
       else if ($len<63)
        {
         $finalfuncname+=str_repeat(" ",63-$len);
        }
       
       $macro='{strcpy(CvGlobals::getInstance().m_funcname[CvGlobals::getInstance().m_funcname[0].index++].name,"'.$finalfuncname.'");if(CvGlobals::getInstance().m_funcname[0].index==PF_MAXFUNCNAMESDEBUG) {CvGlobals::getInstance().m_funcname[0].index=1;}'.chr(13).chr(10);
       //echo "$classname::$funcname // $macro<br>\n";
       $nameok=true;
       //echo strpos($ac[$i],"\n")." $pos_sk ".$file.'"'.$classname."::".$funcname.'"'."<br>\n";

       $ac[$i]=substr($ac[$i],0,$pos_sk).$macro.substr($ac[$i],$pos_sk+1);
       //echo substr($ac[$i],0,$pos_sk+20)."<br>\n";
       $changed=true;
      }
    }
   if ($changed)
    {
     if (strpos($ac[0],'CvGameCoreDll.h')===false)
      {
       $pos=strpos($ac[0],'#include');
       if ($pos!==false)
        {
         $ac[0]=substr($ac[0],0,$pos).'#include "CvGameCoreDll.h"'.chr(13).chr(10).substr($ac[0],$pos);
        }
      }
     if (strpos($ac[0],'CvGlobals.h')===false)
      {
       $ac[0]=str_replace('#include "CvGameCoreDll.h"','#include "CvGameCoreDll.h"'.chr(13).chr(10).'#include "CvGlobals.h"',$ac[0]);
      }
    }
   if ($changed)
    {
     $contents=implode("::",$ac);
     //unlink($file_path);
     if ($fhandle = @fopen ($file_path, "w"))
      {
       fwrite ($fhandle, $contents);
       fclose ($fhandle);
      }
     else
      {
       echo "Failed to save $file_path<br>\n";
      }
    }
  }
 }
 closedir($dirh); 

foreach ($dirlist as $dirpath)
{
 //process_dir($dirpath,$dirh,$lev+1);
}

}
}
process_dir($Should_be_defined_dirpath);

?>

</body>
</html>